package com.estun.backroundManagementService.modules.process.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estun.backroundManagementService.modules.position.model.Position;
import com.estun.backroundManagementService.modules.position.service.PositionService;
import com.estun.backroundManagementService.modules.process.mapper.ProcessDetailMapper;
import com.estun.backroundManagementService.modules.process.model.ProcessDetail;
import com.estun.backroundManagementService.modules.process.service.ProcessDetailService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@AllArgsConstructor
public class ProcessDetailServiceImpl extends ServiceImpl<ProcessDetailMapper, ProcessDetail> implements ProcessDetailService {

    private final PositionService positionService;

    @Override
    public String getProcessCodeByStationCode(String stationId) {
        Integer positionId = positionService.getOne(new QueryWrapper<Position>().eq("station_id", stationId)).getId();
        List<ProcessDetail> processDetails = list();
        for (ProcessDetail processDetail : processDetails) {
            List<Integer> positionIdList = processDetail.getPositionIdList();
            if (positionIdList.contains(positionId)){
                return processDetail.getCode();
            }
        }
        return null;
    }
}
